package incomeSetting

import (
	"github.com/gofiber/fiber/v2"
	"sg-backend/global"
	"sg-backend/model/paylog"
	"sg-backend/model/user"
)

type _incomeJsonType struct {
	TypeList []string `json:"typeList"`
}

func GetIncomeType(ctx *fiber.Ctx) error {

	// 根据用户ID，获取数据
	var userObj user.User
	r := global.DB.First(&userObj, global.AuthUser.UserId)
	if r.Error != nil {
		return ctx.JSON(fiber.Map{
			"status":  "error",
			"message": "获取用户对象失败！",
		})
	}

	// 获取收入分类json
	var incomeList []paylog.IncomeType
	if err := global.DB.Where("user_id = ?", global.AuthUser.UserId).Find(&incomeList); err.Error != nil {
		return ctx.JSON(fiber.Map{
			"status":  "error",
			"message": "解构收入类型List失败！！",
		})
	}

	// 返回
	return ctx.JSON(fiber.Map{
		"status":  "done",
		"message": "请求成功！",
		"data":    incomeList,
	})
}
